﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFSupplier.Common;
using FFSupplier.Common.Configuration;
using FFSupplier.Common.CustomContext;

namespace FFSupplier.ServiceCore.Factory.Basic
{
    public class SqlConnectionFactory : IFactory<SqlConnection>
    {
        public SqlConnection Create()
        {
            SqlConnection sqlConnection = null;
            ContextObject contextConfigurationDB = new ContextObject(ConstValue.CrmDBConnectionAppSetting);
            string config = (string)contextConfigurationDB.Current;
            if (config == null)
            {
                IConfiguration appSetting = new ConnectionStringsConfiguration();
                config = appSetting.GetConfigurationData(ConstValue.CrmDBConnectionAppSetting);
                contextConfigurationDB.Init(() => config);
            }
            sqlConnection = new SqlConnection(config);
            return sqlConnection;
        }
    }
}
